home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / dp_asmss / rescue.asm < prev    next >
Assembly Source File  |  1996-07-12  |  3KB  |  103 lines

  1. ────────────────────────────────────────────────────────────────────────────────
  2. ;  this program looks for a specified string in all sectors of a partition
  3. ;  i used the program to locate a source of an important program that was
  4. ;  lost due to a harddisk crash that destroyed my fat tables ...
  5. ;  learn from it...it's easy                           - plasmoid/deep/thc
  6. ────────────────────────────────────────────────────────────────────────────────
  7. .model small
  8. .stack 100h
  9. .386
  10. .code
  11. sector_start    equ    0
  12. sector_stop    equ    10235
  13.         jmp    main
  14. ────────────────────────────────────────────────────────────────────────────────
  15. searchstring    proc    near
  16.         mov    cx,0
  17. searchloop:    mov    di,offset string
  18.         mov    si,offset buffer
  19.         add    si,cx
  20.         mov    stringfound,0
  21. stringloop:    mov    al,[di]
  22.         cmp    al,0
  23.         je    endsearch
  24.         cmp    al,[si]
  25.         je    found
  26.         mov    stringfound,-1
  27. found:        inc    di
  28.         inc    si
  29.         jmp    stringloop
  30. endsearch:    inc    cx
  31.         cmp    stringfound,0
  32.         je    success
  33.         cmp    cx,512
  34.         jb    searchloop
  35. success:    ret
  36. searchstring    endp
  37. ────────────────────────────────────────────────────────────────────────────────
  38. writetofile    proc    near
  39.         mov    ah,40h            ; write to file the buffer
  40.         mov    bx,handle
  41.         mov    cx,512
  42.         mov    dx,offset buffer
  43.         int    21h
  44.         ret
  45. writetofile    endp
  46. ────────────────────────────────────────────────────────────────────────────────
  47. openfile    proc    near
  48.         mov    dx,offset rescuefile
  49.         mov    ah,3ch            ; create file
  50.         mov    cx,00
  51.         int    21h
  52.         mov    ah,3dh            ; open file for write
  53.         mov    al,01
  54.         int    21h
  55.         mov    handle,ax
  56.         ret
  57. openfile    endp
  58. ────────────────────────────────────────────────────────────────────────────────
  59. closefile    proc    near
  60.         mov    bx,handle
  61.         mov    ah,3eh
  62.         int    21h
  63.         ret
  64. closefile    endp
  65. ────────────────────────────────────────────────────────────────────────────────
  66. readsector    proc    near
  67.         mov    bp,sp            ; save stack
  68.         mov    al,3            ; 3 - drive: D
  69.         mov    cx,1            ; 1 - one sector only
  70.         mov    dx,sector_number
  71.         mov    bx,offset buffer
  72.         int    25h
  73.         mov    sp,bp            ; restore stack
  74.         ret
  75. readsector    endp
  76. ────────────────────────────────────────────────────────────────────────────────
  77. main:        push    @data
  78.         pop    ds
  79.         call    openfile
  80.  
  81. mainloop:    call    readsector
  82.         call    searchstring
  83.         cmp    stringfound,-1
  84.         je    notfound
  85.         call    writetofile
  86. notfound:    inc    sector_number
  87.         cmp    sector_number,sector_stop+1
  88.         jb    mainloop
  89.  
  90.         call    closefile
  91.         mov    ax,4c00h
  92.         int    21h
  93.  
  94. ────────────────────────────────────────────────────────────────────────────────
  95. .data
  96. stringfound    db    -1
  97. handle        dw    0
  98. rescuefile    db    'rescue.lst',0
  99. sector_number    dw    sector_start
  100. buffer        db     512 dup (0)
  101. string        db    ');',0dh,0ah,0
  102. ────────────────────────────────────────────────────────────────────────────────
  103. end